# $Id: PKGBUILD 82334 2013-01-15 11:35:06Z allan $
# Maintainer: Jonathan Conder <jonno.conder@gmail.com>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>

pkgbase=mythplugins
pkgname=('mythplugins-mytharchive'
         'mythplugins-mythbrowser'
         'mythplugins-mythgallery'
         'mythplugins-mythgame'
         'mythplugins-mythmusic'
         'mythplugins-mythnetvision'
         'mythplugins-mythnews'
         'mythplugins-mythweather'
         'mythplugins-mythweb'
         'mythplugins-mythzoneminder')
pkgver=0.26.0
pkgrel=2
epoch=1
arch=('i686' 'x86_64')
url="http://www.mythtv.org"
license=('GPL')
makedepends=('cdrkit' 'dvdauthor' 'dvd+rw-tools' 'ffmpeg' 'flac' 'libexif'
             'libvorbis' 'mesa' 'mplayer' 'mythtv'
	     'perl-datetime-format-iso8601' 'perl-date-manip' 'perl-image-size'
	     'perl-json' 'perl-libwww' 'perl-soap-lite' 'perl-xml-sax'
	     'perl-xml-simple' 'perl-xml-xpath' 'python2-oauth' 'python-imaging'
	     'python2-pycurl' 'taglib' 'zlib')
source=("ftp://ftp.osuosl.org/pub/mythtv/$pkgbase-$pkgver.tar.bz2"
        'cdparanoia.patch'
        'mtd.rc')
md5sums=('15bd7b2f4173488966f3d761e0eacffa'
         '5de8dd79d0b8a2b006f3c3258938b6b7'
         '476c12ba074794ad7f4ae092bdf949d6')

build() {
  cd "$srcdir/$pkgbase-$pkgver"
  find . -name '*.py' -type f | xargs sed -i 's@^#!.*python$@#!/usr/bin/python2@'

  sed -re 's@/usr/local.*/usr/share@/usr/share@' -i 'mythweb/mythweb.php'
  sed -re 's@cstdio@cstdio>\n#include <unistd.h@' -i 'mythzoneminder/mythzmserver/zmserver.cpp'

  patch -Np1 -i "$srcdir/cdparanoia.patch"

  ./configure --prefix=/usr \
              --enable-all \
              --python=python2
  qmake mythplugins.pro
  make -s
}

package_mythplugins-mytharchive() {
  pkgdesc="Create DVDs or archive recorded shows in MythTV"
  depends=('cdrkit' 'dvdauthor' 'dvd+rw-tools' 'ffmpeg' 'mythtv'
           'python-imaging')

  cd "$srcdir/$pkgbase-$pkgver/mytharchive"
  make INSTALL_ROOT="$pkgdir" install
}

package_mythplugins-mythbrowser() {
  pkgdesc="Mini web browser for MythTV"
  depends=('mythtv')

  cd "$srcdir/$pkgbase-$pkgver/mythbrowser"
  make INSTALL_ROOT="$pkgdir" install
}

package_mythplugins-mythgallery() {
  pkgdesc="Image gallery plugin for MythTV"
  depends=('libexif' 'mythtv')

  cd "$srcdir/$pkgbase-$pkgver/mythgallery"
  make INSTALL_ROOT="$pkgdir" install
}

package_mythplugins-mythgame() {
  pkgdesc="Game emulator plugin for MythTV"
  depends=('mythtv')

  cd "$srcdir/$pkgbase-$pkgver/mythgame"
  make INSTALL_ROOT="$pkgdir" install
}

package_mythplugins-mythmusic() {
  pkgdesc="Music playing plugin for MythTV"
  depends=('mythtv' 'libcdio-paranoia' 'taglib')

  cd "$srcdir/$pkgbase-$pkgver/mythmusic"
  make INSTALL_ROOT="$pkgdir" install
}

package_mythplugins-mythnetvision() {
  pkgdesc="MythNetvision plugin for MythTV"
  depends=('mythtv' 'python2-oauth')

  cd "$srcdir/$pkgbase-$pkgver/mythnetvision"
  make INSTALL_ROOT="$pkgdir" install
}

package_mythplugins-mythnews() {
  pkgdesc="News checking plugin for MythTV"
  depends=('mythtv')

  cd "$srcdir/$pkgbase-$pkgver/mythnews"
  make INSTALL_ROOT="$pkgdir" install
}

package_mythplugins-mythweather() {
  pkgdesc="Weather checking plugin for MythTV"
  depends=('mythtv' 'perl-date-manip' 'perl-json' 'perl-soap-lite'
           'perl-xml-sax' 'perl-xml-simple' 'perl-xml-xpath' 'perl-image-size'
           'perl-datetime-format-iso8601')

  cd "$srcdir/$pkgbase-$pkgver/mythweather"
  make INSTALL_ROOT="$pkgdir" install
}

package_mythplugins-mythweb() {
  pkgdesc="Web interface for the MythTV scheduler"
  depends=('mythtv')
  optdepends=('lighttpd'
              'php-apache')
  install='mythplugins-mythweb.install'

  mkdir -p "$pkgdir/var/lib/mythtv/mythweb"/{image_cache,php_sessions}
  cp -R "$srcdir/$pkgbase-$pkgver/mythweb"/* "$pkgdir/var/lib/mythtv/mythweb"
  chown -R http:http "$pkgdir/var/lib/mythtv/mythweb"
  chmod g+rw "$pkgdir/var/lib/mythtv/mythweb"/{image_cache,php_sessions}
}

package_mythplugins-mythzoneminder() {
  pkgdesc="View CCTV footage from zoneminder in MythTV"
  depends=('mythtv')
  install='mythplugins-mythzoneminder.install'

  cd "$srcdir/$pkgbase-$pkgver/mythzoneminder"
  make INSTALL_ROOT="$pkgdir" install
}
